<template>
  <!-- <div class='container'>精选题库</div> -->
  <div>
    <el-card class="box-card">
 
      <el-row type="flex">
        <el-col :span="24">
          <el-form ref="form" :model="form" :inline="true" label-width="80px">
            <el-form-item label="关键字">
              <el-input style="width: 250px" placeholder="根据编号搜索" v-model="form.keyword"></el-input>
            </el-form-item>
            <div  style="float: right">
            <el-button>清除</el-button>
            <el-button type="primary" @click="search">搜索</el-button>
            </div>
          </el-form>
          <el-alert
            :title= sum
            type="info"
            show-icon>
          </el-alert>
          <!-- 表格 -->
          <el-table
            :data="tableData"
            style="width: 100%">
            <el-table-column
              prop="id"
              label="编号"
              width="180">
            </el-table-column>
            <el-table-column
              label="题型"
              align="center"
              width="180">
              <template slot-scope="scope">
                {{ scope.row.questionType === '1' ? '单选' : scope.row.questionType === '2' ? '多选' : '简答' }}
              </template>
            </el-table-column>
            <el-table-column
              prop="address"
              width="200"
              label="题目编号">
              <template slot-scope="scope">
                <div v-for="(val,index) in scope.row.questionIDs" :key="index">
                  <a @click="titleDetails(val.id)" style="color: #0399ff" href="#">{{ val.number }}</a>
                </div>
              </template>
            </el-table-column>
            <el-table-column
              prop="addTime"
              label="录入时间">
            </el-table-column>
            <el-table-column
              prop="totalSeconds"
              align="center"
              label="答题时间(s)">
            </el-table-column>
            <el-table-column
              prop="accuracyRate"
              align="center"
              label="正确率(%)">
            </el-table-column>
            <el-table-column
              prop="userName"
              align="center"
              label="录入人">
            </el-table-column>
            <el-table-column
              align="center"
              label="操作">
              <template slot-scope="scope">
                <el-button type="danger" icon="el-icon-delete" circle @click="delTopic(scope.row)"></el-button>
              </template>
            </el-table-column>
          </el-table>
          <!-- /表格 -->
          <!-- 分页 -->
          <el-pagination class="pager" background layout="prev, pager, next, sizes, jumper" :total="total" :page-size="reqParams.pagesize" :current-page="reqParams.page" @current-change="changePager" @size-change="changeSize" :page-sizes="[5,10,20,50]"></el-pagination>
          <!-- /分页 -->
        </el-col>
      </el-row>
    </el-card>

    <!-- 删除弹窗 -->
      <el-dialog
        title="提示"
        :visible.sync="dialogVisible"
        width="30%"
        >
        <span class="el-icon-warning"><span style="color: #606266;font-size: 14px;margin-left: 10px;">此操作将永久删除该标签,是否继续?</span></span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="remDiscipline">确 定</el-button>
        </span>
      </el-dialog>
    <!-- 删除弹窗 -->

    <!-- 题目编号弹窗 -->
    <el-dialog
      title="题目预览"
      :visible.sync="titleNumber"
      width="70%"
      >
        <el-descriptions title="" :column= '5'>
          <el-descriptions-item label="【题型】">{{ list.questionType === '1' ? '单选' : list.questionType === '2' ? '多选' : '简答' }}</el-descriptions-item>
          <el-descriptions-item label="【编号】">{{ list.id }}</el-descriptions-item>
          <el-descriptions-item label="【难度】">{{ list.difficulty === '1' ? '简单' : list.difficulty === '2' ? '一般' : '困难'}}</el-descriptions-item>
          <el-descriptions-item label="【标签】">{{ list.tags }}</el-descriptions-item>
          <el-descriptions-item label="【学科】">{{ list.subjectID }}</el-descriptions-item>
          <el-descriptions-item label="【目录】">{{ list.catalogID }}</el-descriptions-item>
          <el-descriptions-item label="【方向】">{{ list.direction }}</el-descriptions-item>
        </el-descriptions>
          <template>
            <el-divider></el-divider>
          </template>
          <el-descriptions :column= '1' >
          <el-descriptions-item label="【题干】">{{ list.question }}</el-descriptions-item>
          <el-descriptions-item label="选项：（以下选中的为正确答案）">
          </el-descriptions-item>
          </el-descriptions>
          <template>
              <div>
                <el-radio v-if="list.questionType === '1' ? true : false " v-model="radio" label="A">备选项</el-radio>
                <el-checkbox v-else-if="list.questionType === '2' ? true : false " v-model="checked">备选项</el-checkbox>
              </div>
              <div>
                <el-radio v-if="list.questionType === '1' ? true : false " v-model="radio" label="B">备选项</el-radio>
                <el-checkbox v-else-if="list.questionType === '2' ? true : false " v-model="checked1">备选项</el-checkbox>
              </div>
              <div>
                <el-radio v-if="list.questionType === '1' ? true : false " v-model="radio" label="C">备选项</el-radio>
                <el-checkbox v-else-if="list.questionType === '2' ? true : false " v-model="checked2">备选项</el-checkbox>
              </div>
              <div>
                <el-radio v-if="list.questionType === '1' ? true : false " v-model="radio" label="D">备选项</el-radio>
                <el-checkbox v-else-if="list.questionType === '2' ? true : false " v-model="checked3">备选项</el-checkbox>
              </div>
              <el-divider></el-divider>
            </template>
            <el-descriptions>
          <el-descriptions-item label="【参考答案】">
            <el-button @click="videoOK = !videoOK" type="danger">答案视频预览</el-button>
            <template>
            
            </template>
            </el-descriptions-item>
          </el-descriptions>
            <template>
                <video v-if="videoOK"  :src="list.videoURL" controls ></video>
              <el-divider></el-divider>
            </template>
            <el-descriptions>
              <el-descriptions-item label="【答案解析】">
                {{ list.answerID }}
              </el-descriptions-item>
            </el-descriptions>
            <template>
              <el-divider></el-divider>
            </template>
            <el-descriptions>
              <el-descriptions-item label="【题目备注】">{{ list.remarks }}</el-descriptions-item>
            </el-descriptions>
        <span style="position: relative" slot="footer" class="dialog-footer">
          <el-button class="btn" type="primary" @click="titleNumber = false">关闭</el-button>
        </span>
    </el-dialog>
    <!-- 题目编号弹窗 -->

  </div>
</template>

<script>
import { randoms, removeRandoms, detail,list } from '../../api/hmmm/questions'
import {simple} from '../../api/hmmm/subjects'
import {simple as directory} from '../../api/hmmm/directorys'
import {simple as tag} from '../../api/hmmm/tags'
import {simple as users} from '../../api/base/users'
import {provinces,citys} from '../../api/hmmm/citys'
import {difficulty,questionType,direction} from '../../api/hmmm/constants'

export default {
  name : 'Randoms',
  data() {
    return {
    
      form: {
        keyword: ''
      },
      tableData: [], // 组题数据
      sum: '', // 一共多少数据
      reqParams: {
        subjectName: null,
        page: 1,
        pagesize: 10
      },
      total: 0,
      dialogVisible: false, // 开关删除弹窗
      dleId: '', // 删除当前数据的id
      titleNumber: false, // 题目编号弹窗 
      details: {
        id: ''
      }, // 题目详情数据ID
      // 铺设详情数据
      list : '',
      videoOK : false, // 视频弹出
      radio: 'A', // 单选多选
      checkedList: {
        checked: true,
        checked1: true,
        checked2: false,
        checked3: true
      }
    }
  },
  created () {
    this.randoms()
   
  },
  methods: {
   
    // 分页方法
    changePager (newPage) {
      this.reqParams.page = newPage
      this.randoms()
    },
    // 改变尺码
    changeSize (newSize) {
      this.reqParams.page = 1
      this.reqParams.pagesize = newSize
      this.randoms()
    },
    // 组题数据
    async randoms () {
      try {
        const ret =  await randoms(this.reqParams)
        this.tableData = ret.data.items
        this.total = ret.data.counts
        // console.log('组题数据', this.tableData)
        this.sum = `一共${ret.data.counts}条数据` 
      } catch (error) {
        console.log('error', error)
      }
    },
    // 搜索组题
    async search () {
      try {
        const ret = await randoms(this.form)
        this.tableData = ret.data.items
      } catch (error) {
        console.log('err: ', error)
      }
    },
    // 删除组题
    delTopic (data) {
      this.dialogVisible = true
      this.dleId = data
    },
    async remDiscipline () {
      try {
        const ret = await removeRandoms(this.dleId)
        this.randoms()
        this.$message.success('删除成功')
        this.dialogVisible = false
      } catch (error) {
        this.$message.error('删除失败')
      }
    },
    // 题目详情
    async titleDetails (id) {
      try {
        this.titleNumber = true
        this.videoOK = false
        this.details.id = id
        const ret = await detail(this.details)
        this.list = ret.data
        console.log('成功的回调', this.list)
      } catch (error) {
        console.log('err:', error)
      }
      
    },
  }
}
</script>

<style scoped lang='scss'>
 .pager {
  float: right;
  margin: 10px;
 }
 .el-icon-warning {
  font-size: 23px;
  color: #e6a23c;
  margin-right: 10px;
  padding-bottom: -5px;
}
.el-divider {
  margin: 10px;
}
.btn {
  position: absolute;
  bottom: 0px;
  right: -340px;
}
</style>
